package cn.itlaobing.springmvc.web.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import cn.itlaobing.springmvc.entity.Account;
import cn.itlaobing.springmvc.web.controller.SessionController;

/**
 * 认证
 * @author classA-43
 *
 */
public class AuthorizationInterceptor extends HandlerInterceptorAdapter{

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		//取得当前用户
		HttpSession session =request.getSession();
		Account account = (Account) session.getAttribute(SessionController.CURRENT_ACCOUNT);
		if(account==null){//没有登录
			//重定向  去登录页面
			response.sendRedirect(request.getContextPath()+"/signIn");
			
			return false;
		}
		return true;
	}
	

}
